package password

import (
	"fmt"
	"github.com/alexandrevicenzi/unchained"
	"github.com/simplechain-org/client/log"
)

func Encode(password string, saltSize int, hasher string) string {
	hash, err := unchained.MakePassword(password, unchained.GetRandomString(saltSize), hasher)
	if err != nil {
		log.Error(fmt.Sprintf("Error encoding password: %s\n", err.Error()))
	}
	return string(hash)
}

func Validate(password, cryto string) bool {
	valid, err := unchained.CheckPassword(password, cryto)
	if err != nil {
		log.Error(fmt.Sprintf("Error decoding password: %s\n", err.Error()))
	}
	return valid
}
